﻿<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<body class="easyui-layout">
<div data-options="region:'center',border:false" style="padding:2px;height: auto">
	<table id="role_list_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="
		   	 rownumbers:true,
		   	 pagination:true,
		   	 singleSelect:true,
		   	 toolbar : '#tb',
		   	 fitColumns : true,
		   	 url:'/role-list-json/1/10',
           method:'get',
           onLoadSuccess:function(data){
                $('.edit').linkbutton({plain:true,iconCls:'icon-edit'});
                $('.delete').linkbutton({plain:true,iconCls:'icon-remove'});
                $('.assign').linkbutton({plain:true,iconCls:'icon-wrench'});
           },
           showFooter: true"
		>
		<thead>
		<tr>
			<th data-options="field:'id',width:25,align:'center',formatter:operation">操作</th>
			<th data-options="field:'roleName',width:90,align:'center'">角色名称</th>
			<th data-options="field:'rights',width:90,align:'center'" >权限码</th>
			<th data-options="field:'btnRights',width:90,align:'center'" >权限码</th>
        </tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:5px;height:auto">
	<#include "/common/button.html">
</div>
<div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
    <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
        <div style="margin-bottom:10px">
            <input name="roleName" class="easyui-textbox" required="true" label="角色名称:" missingMessage="请输入角色名称" style="width:100%">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>


<script type="text/javascript">

    //新增
    $("#add").click(function () {
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增角色');
        $('#fm').form('clear');
        url = '/role-ins-upd-del/-1';
    })
    var url;
    function operation(value,row) {
        var rjson = JSON.stringify(row)
        var button ='';
        button += '<a href="#" class="edit" title="编辑" onclick=\'edit('+value+','+rjson+')\'></a>  ' ;
        button += '<a href="#" class="delete" title="删除" onclick=\'del('+value+','+rjson+')\'></a>';
        button += '<a href="#" class="assign" title="分配权限" onclick=\'assign('+value+','+rjson+')\'></a>';
        return button;
    }
    function edit(value,row){
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑');
        $('#fm').form('load',row);
        url = '/role-ins-upd-del/'+row.id;
    }
    function del(value,row){
        url = '/role-ins-upd-del/'+row.id;
        $.messager.confirm('删除信息','确定删除此角色?',function(r){
            if (r){
                $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){
                    console.log('aaa');
                    $('#role_list_table').datagrid('reload');    // reload the user data
                });
            }
        });
    }
    function assign(value,row){
        var url = '/assign-add/'+row.rights+'/'+row.btnRights+'/'+value;
        var index = layer.open({
            title:'用户修改',
            type: 2,
            area: ['700px', '450px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    }
    //保存
    function saveUser(){
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                $('#dlg').dialog('close');        // close the dialog
                $('#role_list_table').datagrid('reload');    // reload the user data
            }
        });
    }
</script>
